using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using cs2335.CCT;
//using cs2335.Images;

namespace cs2335.lab5
{
    class Lab5Demo : CCTForm
    {
        System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer();
        System.Windows.Forms.Timer picTimer = new System.Windows.Forms.Timer();
        ListBox picList = new ListBox();
        System.Collections.ArrayList alist = new System.Collections.ArrayList();
        SpriteStore sStore = new SpriteStore();
        int selectedPic;
        ProgressBar pb = new ProgressBar();
        TextBox tb = new TextBox();
        DomainUpDown domain = new DomainUpDown();
        Label reverse = new Label();
        Button reverseButton = new Button();

        Button imageButton = new Button();
        TreeView tv = new TreeView();


        public Lab5Demo()
        {
            this.Width = 900;
            this.Height = 600;

            string cat = "cat.jpg";
            string face = "face.jpg";
            string gt = "gt.jpg";
            string larry = "larry.jpg";
            string owned = "owned.jpg";
            string pwned = "pwned.jpg";
            string pwned3 = "pwned3.jpg";
            string smiley = "smiley.jpg";
            string blank = "No Picture";

            alist.Add(cat);
            alist.Add(face);
            alist.Add(gt);
            alist.Add(larry);
            alist.Add(owned);
            alist.Add(pwned);
            alist.Add(pwned3);
            alist.Add(smiley);
            alist.Add(blank);
            picList.Items = alist;

            picList.Location = new Point(10, 100);
            //picList.Click += new EventHandler(picList_Click);
            picList.Show();


            reverseButton.Text = "Reverse";
            reverseButton.Click += new EventHandler(reverseButton_Click);
            reverseButton.Location = new Point(160, 15);
            
            alist = new System.Collections.ArrayList();
            for (int i = 0; i < 101; i += 1)
                alist.Add(i.ToString());
            domain.Items = alist;
            domain.Location = new Point(10, 60);
            tb.Location = new Point(10, 20);

            reverse.Font = new Font("SansSerif", 10);
            reverse.Location = new Point(275, 15);
            reverse.Text = "";

            pb.Step = 1;
            pb.Minimum = 0;
            pb.Maximum = 100;
            pb.Location = new Point(130, 60);
            pb.Value = 0;

            domain.Click += new EventHandler(domain_Click);
            domain.KeyDown += new EventHandler(domain_KeyDown);

            imageButton.Text = "Update Image";
            imageButton.Click += new EventHandler(imageButton_Click);
            imageButton.Location = new Point(10, 220);



            sStore.Add("Images/pwned.jpg");
            sStore.Add("Images/cat.jpg");
            sStore.Add("Images/face.jpg");
            sStore.Add("Images/gt.jpg");
            sStore.Add("Images/larry.jpg");
            sStore.Add("Images/owned.jpg");
            sStore.Add("Images/pwned3.jpg");
            sStore.Add("Images/smiley.jpg");
            sStore.setSprite("Images/pwned.jpg");
            sStore.Sprite.Location = new Point(200, 100);


            //Create the nodes for the major polygon catagories
            TreeNode triangle = (TreeNode)tv.Nodes.Add("Triangle");
            TreeNode quadrilateral = (TreeNode)tv.Nodes.Add("Quadrilateral");
            TreeNode pentagon = (TreeNode)tv.Nodes.Add("Pentagon");
            TreeNode hexagon = (TreeNode)tv.Nodes.Add("Hexagon");

            //Add to the quadrilateral catagory
            quadrilateral.Nodes.Add("Trapezium");
            TreeNode rectangle = (TreeNode)quadrilateral.Nodes.Add("Rectangle");
            rectangle.Nodes.Add("Square");
            quadrilateral.Nodes.Add("Rhombus");


            this.Add(tb);
            this.Add(reverseButton);
            this.Add(reverse);
            this.Add(domain);
            this.Add(pb);
            this.Add(picList);
            this.Add(imageButton);
            this.Add(sStore.Sprite);

            //Create a TreeView and add it to the CCT form

            this.Add(tv);


            
        }

        /* REASON: useless.
        void picList_Click(object sender, EventArgs e)
        {
            selectedPic = picList.GetSelected();
            System.Console.WriteLine("you clicked me!");
            System.Console.WriteLine(selectedPic);



        }
        */


        void domain_Click(object sender, EventArgs e)
        {
            pb.Value = Convert.ToInt32(domain.Text);
            this.Invalidate();
        }

        void domain_KeyDown(object sender, EventArgs e)
        {
            domain_Click(sender, e);
        }

        void reverseButton_Click(object sender, EventArgs e)
        {
            timer.Enabled = true;
            String s = "";
            for (int i = tb.Text.Length - 1; i >= 0; i--)
                s += tb.Text[i];
            reverse.Text = s;
        }


        void imageButton_Click(object sender, EventArgs e)
        {
            selectedPic = picList.GetSelected();
            switch (selectedPic)
            {
                // cat face gt larry no pic owned pwned pwned3 smiley
                case -1: goto case 4;
                case 0: sStore.setSprite("Images/cat.jpg");
                    goto case 9;
                case 1: sStore.setSprite("Images/face.jpg");
                    goto case 9;
                case 2: sStore.setSprite("Images/gt.jpg");
                    goto case 9;
                case 3: sStore.setSprite("Images/larry.jpg");
                    //System.Console.WriteLine("case 3 w00t");
                    goto case 9;
                case 4: sStore.Sprite.Hide();
                    break;
                case 5: sStore.setSprite("Images/owned.jpg");
                    goto case 9;
                case 6: sStore.setSprite("Images/pwned.jpg");
                    goto case 9;
                case 7: sStore.setSprite("Images/pwned3.jpg");
                    goto case 9;
                case 8: sStore.setSprite("Images/smiley.jpg");
                    goto case 9;
                case 9: sStore.Sprite.Show();
                    break;
                default: break;
            }
            Invalidate();
        }


        public static void Main()
        {
            System.Windows.Forms.Application.Run(new Lab5Demo());
        }

        private void InitializeComponent()
        {
            this.SuspendLayout();
            // 
            // Demo1
            // 
            this.ClientSize = new System.Drawing.Size(284, 264);
            this.Name = "Lab5Demo";
            this.ResumeLayout(false);

        }
    }
}
